home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / C++ AppleLink Messages / CPlus.Dev$ 4⁄27⁄90 / 0106-Copy Cconstructors &-Apr90 < prev    next >
Encoding:
Text File  |  1990-04-23  |  1.1 KB  |  40 lines  |  [TEXT/GEOL]

  1. Item    9284939                         23-April-90        11:34PDT
  2.  
  3. From:   DEREK                           White, Derek
  4.  
  5. To:     CPLUS.DEV$                      C++ Interest List--Developers
  6.         CPLUS.APPLE$                    C++ Interest List--Apple Employees
  7.  
  8. Sub:    Copy Cconstructors & op=
  9.  
  10.     My latest thoughts have been about copy constructors and assignment
  11. operators.  I've seen sugestions in several places that if you define one you
  12. should define the other, but I don't know how (or if) they should differ.  If
  13. they should be the same, couldn't (shouldn't) the copy constructor just call
  14. the assignment operator to keep down on redundant code?:
  15.  
  16. class TRect {
  17.     int fint;
  18. public:
  19.     TRect(const TRect& r);
  20.     virtual TRect& operator=(const TRect& r);
  21. };
  22.  
  23. TRect::TRect(const TRect& r)
  24. {
  25.     *this = r; // "TRect::operator=(r)"
  26. }
  27.  
  28. TRect& TRect::operator=(const TRect& r)
  29. {
  30.     fint = r.fint;  // etc...
  31.     return *this;
  32. }
  33.  
  34.     As a second issue, does someone have a short example of how virtual
  35. assignment operators can be used even though they aren't inherited?
  36.  
  37. Thanks,
  38. Derek White
  39.  
  40.